﻿Public Class Isci

	Dim View As Integer = 0
	Dim Month As String

	Sub New()
		InitializeComponent()
		ToolBar.Renderer = New FirefoxRenderer
		MnuView0.PerformClick()
	End Sub

	Sub Populate()
		List.DataSource = Service.Liste(Kullanici.TBirim, View, Month)
	End Sub

	Sub Populate(ByVal rowid As Integer)
		Populate()
		Dim Row = (From r As DataGridViewRow In List.Rows Where r.Cells("rowid").Value = rowid).FirstOrDefault
		If Row Is Nothing Then Return
		Row.Highlight()
	End Sub

	Private Sub BtnView_DropDownItemClicked(ByVal sender As Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles BtnView.DropDownItemClicked
		Dim c = Strings.Right(e.ClickedItem.Name, 1)
		If Not IsNumeric(c) Then Return
		BtnView.Text = e.ClickedItem.Text
		View = c
		Populate()
	End Sub

	Private Sub MnuEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MnuEdit.Click
		If List.SelectedRows.Count <> 1 Then Return
		Dim Form As New FrmKart(List.SelectedRows(0).Cells("rowid").Value)
		If Form.ShowDialog <> Windows.Forms.DialogResult.OK Then Return
		Populate(Form.Record.rowid)
	End Sub

	Private Sub List_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles List.DoubleClick
		MnuEdit.PerformClick()
	End Sub

	Private Sub List_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles List.KeyDown
		If e.KeyData = Keys.Enter Then
			MnuEdit.PerformClick()
			e.Handled = True
		End If
	End Sub

	Private Sub MnuNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MnuNew.Click, BtnNew.Click
		Dim Form As New FrmKart()
		If Form.ShowDialog = Windows.Forms.DialogResult.Cancel Then Return
		Populate(Form.Record.rowid)
	End Sub

	Private Sub MnuDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MnuDelete.Click
		If List.SelectedRows.Count <> 1 Then Return
		If Not Confirm("Bu kaydı silmek istediğinizden emin misiniz?") Then Return
		Table.Delete("istihdam", List.SelectedRows(0).Cells("rowid").Value)
		Populate()
	End Sub

	Private Sub MnuMonths_DropDownItemClicked(ByVal sender As Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles MnuMonths.DropDownItemClicked
		Month = e.ClickedItem.Text.Substring(0, 7)
		View = 3
		Populate()
		BtnView.Text = Month & " ayı başvuruları"
	End Sub

	Private Sub MnuMonths_DropDownOpening(ByVal sender As Object, ByVal e As System.EventArgs) Handles MnuMonths.DropDownOpening
		MnuMonths.DropDownItems.Clear()
		Dim Rs = Service.Aylar(Kullanici.TBirim)
		Do Until Rs.EOF
			If Not IsDBNull(Rs(0)) Then MnuMonths.DropDownItems.Add(Mid(Rs(0), 1, 4) & "/" & Mid(Rs(0), 5, 2) & " (" & Rs(1) & " adet)")
			Rs.MoveNext()
		Loop
	End Sub

	Private Sub MnuExit_Click(sender As System.Object, e As System.EventArgs) Handles MnuExit.Click
		FindForm.Close()
	End Sub

	Private Sub MnuAbout_Click(sender As System.Object, e As System.EventArgs) Handles MnuAbout.Click
		Dim Form As New AboutForm
		Form.ShowDialog()
	End Sub

	Private Sub MnuMeslek_Click(sender As System.Object, e As System.EventArgs) Handles MnuMeslek.Click
		FrmMeslekler.ShowDialog()
	End Sub

End Class
